const _ = require('lodash')

module.exports = class Configuration {
    constructor({
        httpConcurrent,
        httpDelay,
        httpTimeout,
        httpRetry,

        referer,
        useragents,

        cacheSeconds,
        fileCacheDir,

        logDir,
        logLevel,
        consoleLogLevel,
        logFileName,

        spidersDir,
    }) {
        this.httpConcurrent = _.defaultTo(httpConcurrent, 3)
        this.httpDelay = _.defaultTo(httpDelay, 1000)
        this.httpTimeout = _.defaultTo(httpTimeout, 5000)
        this.httpRetry = _.defaultTo(httpRetry, 2)

        this.referer = _.defaultTo(referer, '')
        this.useragents = _.compact(_.flatten([useragents]))

        this.cacheSeconds = _.defaultTo(cacheSeconds, 10 * 24 * 3600)
        this.fileCacheDir = _.defaultTo(fileCacheDir, 'storage/caches')

        this.logDir = _.defaultTo(logDir, 'storage/logs')
        this.logLevel = _.defaultTo(logLevel, 'info')
        this.consoleLogLevel = _.defaultTo(_.defaultTo(consoleLogLevel, logLevel), 'verbose');
        this.logFileName = _.defaultTo(logFileName, 'app.log')

        this.spidersDir = _.defaultTo(spidersDir, 'spiders')
    }
}